package Lee_code;

public class Lee_35 {
    public int searchInsert(int[] nums, int target) {
        int len = nums.length;
        int left = 0;
        int right = target - 1;
        while (left < right)
        {
            int mid = right + (left - right) / 2;
            if(nums[mid] == target)
                return mid;

            else if(nums[mid] < target)
                left = mid + 1;

            else if (nums[mid] > target) {
                right = mid - 1;
            }
        }
        return nums[left] >= target ? left : left + 1;
    }
}
